package com.itcms.webservice.uuv.org;

import java.util.List;

import javax.xml.namespace.QName;

import org.apache.cxf.binding.soap.SoapHeader;
import org.apache.cxf.binding.soap.SoapMessage;
import org.apache.cxf.binding.soap.interceptor.AbstractSoapInterceptor;
import org.apache.cxf.headers.Header;
import org.apache.cxf.helpers.DOMUtils;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.phase.Phase;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class ClientAuthInterceptor extends AbstractSoapInterceptor{
	public ClientAuthInterceptor(){  
        super(Phase.WRITE);  
    }  
       
    public void handleMessage(SoapMessage soapMessage) throws Fault {  
        Document doc=DOMUtils.createDocument();  
        // 根节点  
        Element rootEle=doc.createElementNS("", "ESBSecurityToken");  
        // 用户ID  
        Element userEle = doc.createElement("username");  
        userEle.setTextContent("OutNewAdmin");  
        rootEle.appendChild(userEle);  
        // 密码  
        Element passEle = doc.createElement("password");  
        passEle.setTextContent("489D717670E16B00D9CA9EEDA037F529");  
        rootEle.appendChild(passEle);
        // 时间 
        Element timeEle = doc.createElement("timestamp");  
        passEle.setTextContent("2017-04-23 10:15:55");  
        rootEle.appendChild(timeEle);  
        // 添加到头  
        List<Header> headers = soapMessage.getHeaders();  
        QName qname=new QName("ESBSecurityToken");  
        SoapHeader head=new SoapHeader(qname, rootEle);  
        headers.add(head);  
    }  
}
